/ Assembly List / LJCNetCommon / NetCommon / CompareNull

Namespace - LJCNetCommon


Parameters
x - The compare object.
y - The compare to object.

Returns

The integer that indicates the order relationship of the objects.

Syntax

C#
public static Int32 CompareNull(Object x, Object y)

Compare null values. (DE)

Remarks

-2 - Neither object is null.
-1 - Null object x precedes object y.
0 - Object x and object y are both null.
1 - Object x follows null object y.

Example

C#
using System;
using LJCNetCommon;
        
<span class='xmlComment'>/// <summary>Sort and search on Name value.</summary></span>
public class NameComparer : IComparer<ClassName>
{
    // Compares two objects.
    /// <include path='items/Compare/*' file='../../../CoreUtilities/LJCGenDoc/Common/Data.xml'/>
    public int Compare(ClassName x, ClassName y)
    {
        int retValue;

        retValue = NetCommon.CompareNull(x, y);
        if (-2 == retValue)
        {
            retValue = NetCommon.CompareNull(x.Name, y.Name);
            if (-2 == retValue)
            {
                // Case sensitive.
                //retValue = x.Name.CompareTo(y.Name);

                // Not case sensitive.
                retValue = string.Compare(x.Name, y.Name, true);
            }
        }
        return retValue;
    }
}

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.